package nl.hanze.designpatterns.DAO.impl.db;

import java.util.Iterator;

import nl.hanze.designpatterns.DAO.LoginCredentialDAO;
import nl.hanze.designpatterns.domain.LoginCredential;

public class LoginCredentialsDaoImpl extends BaseDaoImpl implements LoginCredentialDAO {

	@Override
	public boolean isValid(LoginCredential logincredential) {
		Iterator<LoginCredential> credentials = null;
		try{
			credentials = executor.getIterator("SELECT * FROM logincredentials", LoginCredential.class);
			while(credentials.hasNext()){
				if(credentials.next().toString().equals(logincredential.toString())){
					logincredential.setUserId(credentials.next().getUserId());
					return true;
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return false;
	}
	

}
